package md.lanjing.com.module_home.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.ToastUtils;

import md.lanjing.com.module_home.R;
import md.lanjing.com.module_home.api.HomeApiService;
import md.lanjing.com.module_home.bean.LoginRequest;
import md.lanjing.com.module_home.bean.LoginResponse;
import retrofit2.Call;
import retrofit2.Response;

public class LoginContact {

    public static class LoginPresent extends BasePresent<ILoginView> {
            public void login(final Context context, String phone, String pwd){
                HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
                LoginRequest request=new LoginRequest(phone, pwd);
                service.login(request).enqueue(new NetCallBack<LoginResponse>() {
                    @Override
                    public void onSuccess(Call<LoginResponse> call, Response<LoginResponse> response) {
                        if (getView()!=null){
                            getView().getLoginData(response);
                        }
                    }

                    @Override
                    public void onFailed() {
                        ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                    }
                });

            }
    }


    public interface ILoginView extends IBaseView {
          void getLoginData(Response<LoginResponse> response);
    }
}
